import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

// 工作台
import worktable from './modules/worktable'
// 园区管理
import park from './modules/park'
// 行车管理
import car from './modules/car'
// 物业费管理
import homeowners from './modules/homeowners'
// 一体杆管理
import integrated from './modules/integrated'
// 系统管理
import systems from './modules/systems'

Vue.use(Router)

export const constantRoutes = [{
  path: '/login',
  component: () =>
    import ('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () =>
    import ('@/views/404'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  redirect: '/worktable',
  children: [{
    path: 'worktable',
    name: 'Worktable',
    component: () =>
      import ('@/views/worktable/index'),
    meta: { title: '工作台', icon: 'worktable' }
  }]
},

worktable,
park,
car,
homeowners,
integrated,
systems,

{ path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
